package com.easy.dfc.service;

import com.easy.common.bean.Result;
import com.easy.common.constant.EnumConfig;
import com.easy.dfc.entity.AnswerQuestion;
import com.easy.dfc.entity.AskOther;
import com.easy.dfc.entity.ReplyAnswer;
import com.easy.dfc.mapper.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DealerHomeService {

    @Resource
    private DfcAdvertisementMapper dfcAdvertisementMapper;

    @Resource
    private AskOtherMapper askOtherMapper;

    @Resource
    private ProductsetMapper productsetMapper;

    @Resource
    private DfcOrdersMapper dfcOrdersMapper;

    @Resource
    private DfcOrderItemMapper dfcOrdersItemsMapper;

    @Resource
    private DfcLiveMapper dfcLiveMapper;

    @Resource
    private FactorySetMapper factorySetMapper;

    public Result HomePage() {
        Integer askSize = 5; //风车话题前五
        Integer productSize = 4;//天天焕新 前4
        Integer factorySize = 4;//好厂推荐 前4
        Integer niceFactoryProductSize = 10;

        List<Map<String,Object>> bannerList = dfcAdvertisementMapper.getHomeBanner();////顶部轮播
        List<Map<String,Object>> askOtherList = askOtherMapper.getNewList(askSize);//风车话题前五
        List<Map<String,Object>> newProductList = productsetMapper.getNewProductList(productSize);//天天焕新
        List<Map<String,Object>> niceFactoryList = factorySetMapper.getNiceFactoryList(factorySize);//好厂推荐，订单最多的店铺

        List<Map<String,Object>> berserkProductList = factorySetMapper.getBerserkProductList(factorySize); //疯抢

        List<Map<String,Object>> liveList =  dfcLiveMapper.getNowLiveList(niceFactoryProductSize);//首页风车直播

        //List<Map<String,Object>> nicebrandList =  factorySetMapper.getNiceBrandList(niceFactoryProductSize);//首页精选品牌
        //List<Map<String,Object>> niceFactoryTodayList = factorySetMapper.getNiceFactoryTodayList(niceFactoryProductSize); //首页每日好厂

        List<Map<String,Object>> nicebrandList =  factorySetMapper.getBrandProSaleMax();//首页精选品牌
        List<Map<String,Object>> niceFactoryTodayList = factorySetMapper.getFactoryProSaleMax(); //首页每日好厂


        Result rt = new Result();
        Map<String,Object> map = new HashMap<String,Object>();
        if(bannerList == null)bannerList = new ArrayList();
        if(liveList == null)liveList = new ArrayList();
        if(askOtherList == null)askOtherList = new ArrayList();
        if(newProductList == null)newProductList = new ArrayList();
        if(niceFactoryList == null)niceFactoryList = new ArrayList();
        if(nicebrandList == null)nicebrandList = new ArrayList();

        map.put("banner",bannerList);
        map.put("askOther",askOtherList);
        map.put("newProduct",newProductList);
        map.put("berserkProduct",berserkProductList);
        map.put("niceFactory",niceFactoryList);
        map.put("liveList",liveList);
        map.put("niceBrand",nicebrandList);
        map.put("niceFactoryToday",niceFactoryTodayList);
        rt.setStatus(EnumConfig.S_CODE.OK);

        rt.setData(map);
        return rt;

    }

    /**
     * 首页精选宝贝
     *  按销量分页获取
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Result NiceProduct(Integer pageIndex, Integer pageSize) {
        Result rt = new Result();
        pageIndex = pageIndex*pageSize;
        List niceProductList = factorySetMapper.getNiceProduct(pageIndex,pageSize); //首页每日好厂
        if(niceProductList == null)niceProductList = new ArrayList();
        rt.setStatus(EnumConfig.S_CODE.OK);
        rt.setData(niceProductList);
        return rt;

    }
}
